//
//  CustomGoUpAndDownView.m
//  Jewelry
//
//  Created by HJ on 2017/1/6.
//  Copyright © 2017年 HJ. All rights reserved.
//

#import "CustomGoUpAndDownView.h"
#import "SDAutoLayout.h"
#import "UIView+Extension.h"
@implementation CustomGoUpAndDownView
{
    UIImageView * oldNewImg;
    UIImageView * popularImg;
    UIImageView * priceImg;
    UIImageView * showPayImg;
    UILabel * oldLabel;
    UILabel * popuLabel;
    UILabel * priceLabel;
    UILabel * showPayLabel;
    BOOL isIS;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if ([super initWithFrame:frame]) {
        NSString*str=@"综合";
        CGSize size=[str sizeWithAttributes:@{NSFontAttributeName:FontAndStyle14}];
        CGFloat width = (MainW)/4;
        CGFloat height = 40;
        
        CGFloat short_X = (size.width);
        CGFloat spacing = (MainW-(size.width+10)*4-20)/3+size.width+10;
        self.OldOrnewBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, height)];
        [self addSubview:self.OldOrnewBtn];
        oldLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 12.5, size.width, 15)];
        oldLabel.text= @"综合";
        //oldLabel.backgroundColor=[UIColor redColor];
        oldLabel.textColor=[UIColor redColor];
        oldLabel.font = FontAndStyle12;
        [self addSubview:oldLabel];
        oldNewImg = [[UIImageView alloc] initWithFrame:CGRectMake(oldLabel.bsg_x+short_X, oldLabel.bsg_centerY-2.5, 8,5)];
        oldNewImg.image = [UIImage imageNamed:@"composite_arrow"];
        self.oldNewImg=oldNewImg;
        [self addSubview:oldNewImg];
        
        
        self.PopularityBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.OldOrnewBtn.bsg_x+spacing, self.OldOrnewBtn.y, width, height)];
        [self addSubview:self.PopularityBtn];
        popuLabel = [[UILabel alloc] initWithFrame:CGRectMake(oldLabel.bsg_x+spacing, 12.5, size.width, 15)];
        popuLabel.text= @"销量";
        popuLabel.textColor = TextColor3;
        popuLabel.font = FontAndStyle12;
        [self addSubview:popuLabel];
        popularImg = [[UIImageView alloc] initWithFrame:CGRectMake(popuLabel.bsg_x+short_X , popuLabel.bsg_centerY-6, 8, 12)];
        popularImg.image = [UIImage imageNamed:@"sales_arrows_nor"];
        [self addSubview:popularImg];
        
        
        self.priceBtn = [[UIButton alloc]initWithFrame:CGRectMake(MainW/2+10, 0, width, height)];
        [self addSubview:self.priceBtn];
        priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(popuLabel.bsg_x+spacing, 12.5, size.width, 15)];
        priceLabel.text= @"价格";
        priceLabel.textColor = TextColor3;
        priceLabel.font = FontAndStyle12;
        [self addSubview:priceLabel];
        priceImg = [[UIImageView alloc] initWithFrame:CGRectMake(priceLabel.bsg_x+short_X ,priceLabel.bsg_centerY-6, 8, 12)];
        priceImg.image = [UIImage imageNamed:@"sales_arrows_nor"];
        [self addSubview:priceImg];
        self.showPayBtn = [[UIButton alloc]initWithFrame:CGRectMake(MainW*3/4, self.OldOrnewBtn.y, width, height)];
        [self addSubview:self.showPayBtn];
        
        showPayLabel =[[UILabel alloc] initWithFrame:CGRectMake(priceLabel.bsg_x+spacing, 12.5, 50, 15)];
        showPayLabel.font =FontAndStyle12;
        showPayLabel.text = @"筛选";
        showPayLabel.textColor = TextColor3;
        [self addSubview:showPayLabel];
        showPayImg =[[UIImageView alloc] initWithFrame:CGRectMake(showPayLabel.bsg_x+short_X ,showPayLabel.bsg_centerY-5, 8, 10)];
        showPayImg.image = [UIImage imageNamed:@"screen_nor"];
        self.showPayImg=showPayImg;
        self.showPayLabel=showPayLabel;
        [self addSubview:showPayImg];

        self.OldOrnewBtn.backgroundColor =[UIColor whiteColor];
        self.PopularityBtn.backgroundColor =[UIColor whiteColor];
        self.priceBtn.backgroundColor =[UIColor whiteColor];
        self.showPayBtn.backgroundColor =[UIColor whiteColor];
        
        [self.OldOrnewBtn addTarget:self action:@selector(oldOrNewBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.PopularityBtn addTarget:self action:@selector(PopularityBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.priceBtn addTarget:self action:@selector(priceBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.showPayBtn addTarget:self action:@selector(showPayBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return self;
}

-(void)oldOrNewBtnClick{
    oldLabel.textColor=Red_Color;
    self.OldOrnewBtn.selected=!self.OldOrnewBtn.selected;
    if (self.OldOrnewBtn.selected) {
         oldNewImg.image = [UIImage imageNamed:@"composite_arrow"];
    }else{
        
         oldNewImg.image = [UIImage imageNamed:@"composite_arrow_up"];
    }
    //其他按钮的状态
    popuLabel.textColor=TextColor3;
    priceLabel.textColor=TextColor3;
    showPayLabel.textColor=TextColor3;
    popularImg.image=[UIImage imageNamed:@"sales_arrows_nor"];
    priceImg.image=[UIImage imageNamed:@"sales_arrows_nor"];
    showPayImg.image=[UIImage imageNamed:@"screen_nor"];
    [_delegate oldOrNewBtnClick];
    self.PopularityBtn.selected=NO;
    self.priceBtn.selected=NO;
    self.showPayBtn.selected=NO;
}
-(void)PopularityBtnClick{
    [_delegate PopularityBtnClick];
    
    self.PopularityBtn.selected=!self.PopularityBtn.selected;
    popuLabel.textColor=Red_Color;
    if (self.PopularityBtn.selected) {
        popularImg.image = [UIImage imageNamed:@"sales_arrows_pre_down"];
    }else{
        
        popularImg.image = [UIImage imageNamed:@"sales_arrows_pre_up"];
    }
    //其他按钮的状态
    self.OldOrnewBtn.selected=YES;
    self.priceBtn.selected=NO;
    self.showPayBtn.selected=NO;
    oldLabel.textColor=TextColor3;
    priceLabel.textColor=TextColor3;
    showPayLabel.textColor=TextColor3;
    oldNewImg.image=[UIImage imageNamed:@"composite_arrow_nor"];
    priceImg.image=[UIImage imageNamed:@"sales_arrows_nor"];
    showPayImg.image=[UIImage imageNamed:@"screen_nor"];

    
}
-(void)priceBtnClick{
    [_delegate priceBtnClick];
    self.priceBtn.selected=!self.priceBtn.selected;
    priceLabel.textColor=Red_Color;
    if (self.priceBtn.selected) {
        priceImg.image = [UIImage imageNamed:@"sales_arrows_pre_down"];
    }else{
        
        priceImg.image = [UIImage imageNamed:@"sales_arrows_pre_up"];
    }
    //其他按钮的状态
    self.PopularityBtn.selected=NO;
    self.OldOrnewBtn.selected=YES;
    self.showPayBtn.selected=NO;
    oldLabel.textColor=TextColor3;
    popuLabel.textColor=TextColor3;
    showPayLabel.textColor=TextColor3;
    oldNewImg.image=[UIImage imageNamed:@"composite_arrow_nor"];
    popularImg.image=[UIImage imageNamed:@"sales_arrows_nor"];
    showPayImg.image=[UIImage imageNamed:@"screen_nor"];
}
-(void)showPayBtnClick{
    showPayLabel.textColor=Red_Color;
  
    showPayImg.image = [UIImage imageNamed:@"screen_pre"];
    //其他按钮的状态
    [_delegate showPayBtnClick];
}
@end
